import json
from pyecharts.charts import Map
from pyecharts.options import TitleOpts,VisualMapOpts
f = open("E:\excel学习文档-表格\黑马-可视化案例数据\地图-疫情.txt",'r',encoding = "UTF-8")
data = f.read()
data_list = json.loads(data)
yunnan_data = data_list['areaTree'][0]['children'][2]['children']
# print(yunnan_data)

data_list = []
for cities_data in yunnan_data:
    city_data = cities_data['name'] + "市"
    print(city_data)
    if city_data == "昭通市市":
        city_data = "昭通市"

    if city_data == "保山市市":
        city_data = "保山市"

    if city_data == "丽江市市":
        city_data = "丽江市"

    confirm_data = cities_data['total']['confirm']
    data_list.append((city_data,confirm_data))

    data_list.append(("大理白族自治州",400))
# print(data_list)
    # print(confirm_data)
# print(cities_data)
# print(confirm_data)

map = Map()
map.add("云南省疫情地图",data_list,"云南")
map.set_global_opts(
    title_opts = TitleOpts(title = "确诊人数",pos_left = "center",pos_bottom = "1%"),
    visualmap_opts = VisualMapOpts(
        is_show = True,
        is_piecewise = True,
        pieces = (
            {"min":1,"max":100,"label":"1-100人","color":"#00CC00"},
            {"min":101,"max":200,"label":"101-200人","color":"#0099FF"},
            {"min":201,"max":300,"label":"201-300人","color":"#CCCCFF"},
            {"min":301,"max":400,"label":"301-400人","color":"#CC33FF"},
            {"min":401,"max":500,"label":"401-500人","color":"#0033FF"},
            {"min":501,"label":">500人","color":"#9933CC"},
        )
    )
)

map.render("云南省疫情地图.html")